package com.sgzn.sgpay.web.entity;


import lombok.Data;
import lombok.Delegate;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.web.authentication.WebAuthenticationDetails;

import java.util.List;
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = false)
public class WebUser implements Authentication {
    @Delegate
    private SgpayUser sgpayUser;

    /**
     * 密码
     */
    private String password;

    /**
     * 是否已认证
     */
    private boolean isAuthenticated;

    /**
     * 详情
     */
    private WebAuthenticationDetails details;

    /**
     * 权限列表
     */
    private List<GrantedAuthority> authorities;

    /**
     * 登陆后重定向地址
     */
    private String redirectUrl;

    /**
     * 登录方式
     */
    private String loginType;

    /**
     * 是否记录登出日志标识，默认为false
     */
    private boolean loginOutLogFlag = false;

    /**
     * 最后登录IP
     */
    private String lastLoginInIp;

    /**
     * 最后登录时间
     */
    private String lastLoginInDate;

    private String initiationID;

    @Override
    public Object getCredentials() {
        return password;
    }

    @Override
    public Object getPrincipal() {
        return sgpayUser.getUserCode();
    }

    @Override
    public String getName() {
        return sgpayUser.getUserName();
    }

    public WebUser(){}

    public WebUser(String userCode, String password, String randomCode, String redirectUrl, String loginType){
        SgpayUser pUser = new SgpayUser();
        pUser.setUserCode(userCode);
        pUser.setRandomCode(randomCode);
        this.sgpayUser = pUser;
        this.password = password;
        this.redirectUrl = redirectUrl;
        this.loginType = loginType;
    }
}
